from .udp_connet import udp_server
from src import Bypass_port,server_ip,Master_ip_data,dport


def Bypass(device_num:int,value):
    try:
        my_eb = udp_server(server_ip, Bypass_port)  # PC IP
        my_eb.open()
        ub = device_num.to_bytes(4, 'big')
        if value == 1:
            eb_write = [0x50,0x41,0x55,ub[0],ub[1],ub[2],ub[3],
                        0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                        0x00,0x00,0x00,0x00]
        elif value == 0:
            eb_write = [0x50,0x41,0xd5,ub[0],ub[1],ub[2],ub[3],
                        0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                        0x00,0x00,0x00,0x00]
        my_eb.sent_message(eb_write, Master_ip_data["M1 ip"], dport)
        my_eb.sent_message(eb_write, Master_ip_data["M2 ip"], dport)
    except Exception as e:
        print(e)